# Docker Hadoop+Spark运行环境

FROM centos:latest
MAINTAINER zhoucl0220@gmail.com

#清除yum的cache
RUN yum clean dbcache

#安装必要的包
RUN yum install -y wget iproute which openssh-server openssh-clients

#生成sshd的key文件
RUN ssh-keygen -t rsa -P '' -f /etc/ssh/ssh_host_rsa_key
RUN ssh-keygen -t ecdsa -P '' -f /etc/ssh/ssh_host_ecdsa_key
RUN ssh-keygen -t ed25519 -P '' -f /etc/ssh/ssh_host_ed25519_key

RUN mkdir /app

WORKDIR /app

#上传所需的软件包(JDK,Scala,Hadoop,Spark,Sqoop,Hive,Hbase等
ADD ./tgz/* /app/
#解压上传的所有的文件
RUN find -maxdepth 1 -name "*gz"|xargs -i tar zxvf {}
#删除所有的文件
RUN rm -f *gz

#修改root密码
RUN echo root | passwd --stdin root

#创建hadoop用户
RUN useradd hadoop

#设置密码
RUN echo hadoop | passwd --stdin hadoop

#设置权限
RUN chown -R hadoop:hadoop /app

#设置hadoop环境变量
#ENV JAVA_HOME /app/jdk1.8.0_60
#ENV SCALA_HOME /app/scala-2.11.8
#ENV HADOOP_PREFIX /app/hadoop-2.7.2
#ENV HADOOP_HOME /app/hadoop-2.7.2
#ENV HADOOP_CONF_DIR /app/hadoop-2.7.2/etc/hadoop
#ENV HADOOP_HDFS_HOME /app/hadoop-2.7.2
#ENV HADOOP_MAPRED_HOME /app/hadoop-2.7.2
#ENV HADOOP_YARN_HOME /app/hadoop-2.7.2

RUN echo "JAVA_HOME=/app/jdk1.8.0_60" >> /home/hadoop/.bash_profile \
    && echo "SCALA_HOME=/app/scala-2.11.8" >> /home/hadoop/.bash_profile \
    && echo "HADOOP_PREFIX=/app/hadoop-2.7.2" >> /home/hadoop/.bash_profile \
    && echo "HADOOP_HOME=/app/hadoop-2.7.2" >> /home/hadoop/.bash_profile \
	&& echo "HADOOP_COMMON_HOME=/app/hadoop-2.7.2" >> /home/hadoop/.bash_profile \
    && echo "HADOOP_CONF_DIR=/app/hadoop-2.7.2/etc/hadoop" >> /home/hadoop/.bash_profile \
    && echo "HADOOP_HDFS_HOME=/app/hadoop-2.7.2" >> /home/hadoop/.bash_profile \
    && echo "HADOOP_MAPRED_HOME=/app/hadoop-2.7.2" >> /home/hadoop/.bash_profile \
    && echo "HADOOP_YARN_HOME=/app/hadoop-2.7.2" >> /home/hadoop/.bash_profile \
	&& echo "HADOOP_LIBEXEC_DIR=/app/hadoop-2.7.2/libexec" >> /home/hadoop/.bash_profile \
	&& echo "HADOOP_COMMON_LIB_NATIVE_DIR=/app/hadoop-2.7.2/lib/native" >> /home/hadoop/.bash_profile \
	&& echo "JAVA_LIBRARY_PATH=/app/hadoop-2.7.2/lib/native" >> /home/hadoop/.bash_profile \
	&& echo "SQOOP_HOME=/app/sqoop-1.4.6.bin__hadoop-2.0.4-alpha" >> /home/hadoop/.bash_profile \
    && echo "PATH=$PATH:/app/hadoop-2.7.2/sbin:/app/hadoop-2.7.2/bin:/app/jdk1.8.0_60/bin:/app/scala-2.11.8/bin:/app/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/bin" >> /home/hadoop/.bash_profile \
    && echo "export JAVA_HOME SCALA_HOME HADOOP_PREFIX HADOOP_HOME HADOOP_COMMON_HOME HADOOP_CONF_DIR HADOOP_HDFS_HOME HADOOP_MAPRED_HOME HADOOP_YARN_HOME HADOOP_LIBEXEC_DIR HADOOP_COMMON_LIB_NATIVE_DIR JAVA_LIBRARY_PATH SQOOP_HOME PATH" >> /home/hadoop/.bash_profile

#启动初始化
CMD ["/usr/sbin/init"]
